home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / C++ Toolbox 1.0 / QuickDraw++.cp < prev    next >
Text File  |  1995-11-16  |  1KB  |  72 lines

  1. /*
  2.     File:        QuickDraw++.cp
  3.     
  4.     Contains:    C++ extensions to QuickDraw.
  5.     
  6.     Version:    1.0
  7.     
  8.     Copyright:    ©1995 Chris K. Thomas.  All Rights Reserved.
  9. */
  10.  
  11. #include <LDataStream.h>    // * PowerPlant
  12. #include "QuickDraw++.h"
  13.  
  14. //
  15. // construct a ColorSpecTable using flattened ColorTable data
  16. //
  17. ColorSpecTable::ColorSpecTable(LStream &inTableStream)
  18. {
  19.     SInt16        ctSize;
  20.     
  21.     // skip past ctSeed and ctFlags
  22.     inTableStream.SetMarker(sizeof(UInt32) + sizeof(UInt16), streamFrom_Marker);
  23.     
  24.     // read color count
  25.     inTableStream.ReadData(&ctSize, sizeof(SInt16));
  26.     
  27.     Assert_(ctSize > 0);    // sanity check
  28.     
  29.     mColorTable.setcount(ctSize + 1);
  30.     
  31.     // read in colorspecs
  32.     ColorSpec                cSpec;
  33.     
  34.     mColorTable.lock();
  35.     
  36.     for(long curColor = 0; curColor <= ctSize; curColor++)
  37.     {
  38.         inTableStream.ReadData(&cSpec, sizeof(ColorSpec));
  39.         mColorTable[curColor] = cSpec;
  40.     }
  41.     
  42.     mColorTable.unlock();
  43. }
  44.  
  45. //
  46. // LookupIndexColor
  47. // Given an index, return the corresponding color
  48. //
  49. Boolean
  50. ColorSpecTable::LookupIndexedColor(long inIndex, RGBColor &outColor)
  51. {
  52.  
  53.     mColorTable.lock();
  54.     
  55.     long    colorCount = mColorTable.getcount();
  56.     Boolean outFound = false;
  57.  
  58.     for(long curColor = 0; curColor < colorCount; curColor++)
  59.     {
  60.         if(mColorTable[curColor].value == inIndex)
  61.         {
  62.             outColor = mColorTable[curColor].rgb;
  63.             outFound = true;
  64.             break;
  65.         }
  66.     }
  67.     
  68.     mColorTable.unlock();
  69.     
  70.     return outFound;
  71. }
  72.